import React from 'react';
import {Card, Icon, Input, Button, Tooltip, notification} from 'antd';
import {browserHistory} from 'react-router';
import TableView from './TableView';

export default class staffMember extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            findParents: GLOBAL.baseURL + "/webAPI/user/findUserList",
            totalPageNum: 0,
            ServiceData: [],
            searchObject: {},
            nickName: '',
            phone: '',
            loading: false
        };
    }
    serviceError(err){
        this.setState({loading: false});
        notification.error({
            placement: 'bottomRight',
            message: '提示你：',
            description: '对不起，网络错误，请稍候重试。',
            style: {
              borderLeft: '4px solid rgb(240, 70, 52)'
            }
        });
    }
    totalPageNum(num) {
        this.setState({
            totalPageNum: num
        })
    }
    getServiceData(data) {
        this.setState({
            loading: false,
            ServiceData: data
        });
    }
    gotoDetail(uId){
        browserHistory.push("/backstage/staffMember/staffDetail/" + uId);
    }
    renderItem(item, index) {
        var imgHeader = null;
        if (item.photoPic == undefined || item.photoPic == "") {
            imgHeader = <img className="userHead" src='/src/styles/images/default.png'/>
        } else {
            imgHeader = <img className="userHead" src={"http://tinsley.oss-cn-shenzhen.aliyuncs.com/" + item.photoPic} title={item.firstName}/>
        }
        return (
              <Card key={index} className="divItemLine" onClick={this.gotoDetail.bind(this, item.uId)}>
                  <div className="divUserHead">
                      {imgHeader}
                  </div>
                  <div className="userInfo" style={{marginTop: '-3px'}}>
                      <div className="divContent">
                          <span>{'姓名：' + ((item.firstName == undefined)?"":item.firstName) + " " + ((item.lastName == undefined)?"":item.lastName)}</span>
                          <span>{'，性别：' + ((item.gender==1)?"男":"女")}</span>
                      </div>
                      <div className="divContent">
                          <span>{'邮箱：' + ((item.email == undefined)?"":item.email)}</span>
                          <span>{'，年龄：' + ((item.age == undefined)?"":item.age)}</span>
                      </div>
                      <div className="divArticleContent2">
                        <span>{'家庭地址：' + ((item.location == undefined)?"": item.location) + " " + ((item.position == undefined)?"": item.position)}</span>
                      </div>
                      <div className="divArticleContent2">
                        <span>{'个人简介：' + ((item.overview == undefined)?"":item.overview)}</span>
                      </div>
                  </div>
              </Card>
        );
    }
    render() {
        if(this.props.params.id == undefined){
          var serverList = null;
          if(this.state.ServiceData.length != 0){
              serverList = <div style={{marginBottom: '20px'}}>
                {
                    this.state.ServiceData.map((item, index) => {
                        return this.renderItem(item, index);
                    })
                }
              </div>
          }else{
              serverList = <div className="divEmptyData">对不起，没有相关数据。</div>
          }
          return (
              <div>
                  {serverList}
                  <TableView ref="tableView" totalPageNum={this.totalPageNum.bind(this)}
                             isInternalRendering={false} getServiceData={this.getServiceData.bind(this)}
                             isService={true} serviceError={this.serviceError.bind(this)} searchObject={this.state.searchObject} pageNum={10}
                             url={this.state.findParents} method="post"/>

              </div>
          )
        }else {
          return (this.props.children);
        }
    }
}
